package com.btr.ivle.helper;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.btr.ivle.R;

public class ModuleDetailAdapter extends ArrayAdapter<Map<String,String>> {
	
	
	Context context;
	
	public ModuleDetailAdapter(Context context,List<Map<String, String>> list) {
		super(context, 0, list);
		this.context = context;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		ViewGroup vg = parent;
		if (view == null){
			LayoutInflater inflator = (LayoutInflater) this.getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			view = inflator.inflate(R.layout.moduledetailitem_new2, vg, false);
		}
		
		TextView textTitle = (TextView) view.findViewById(R.id.ModuleDetailItemTitle);
		textTitle.setText(this.getItem(position).get("item"));
		if(this.getItem(position).get("item").length()>9){
			textTitle.setTextSize(16);
		}
		
		int type = Integer.valueOf(this.getItem(position).get("type"));
		int imageId;
		
		switch(type){
			case 0:
				imageId = R.drawable.module_bin_w;
				break;
			case 1:
				imageId = R.drawable.module_news_w;
				break;
			case 2:
				imageId = R.drawable.module_forum_w;
				break;
			case 3:
				imageId = R.drawable.module_cast_w;
				break;
			case 4:
				imageId = R.drawable.module_gradebook_w;
				break;
			case 5:
				imageId = R.drawable.module_link_w;
				break;
			default:
				imageId = R.drawable.module_news_w;
		}
		
		ImageView imageView = (ImageView) view.findViewById(R.id.ModuleDetailItemImage);
		imageView.setImageResource(imageId);
		
		TextView textUnread = (TextView) view.findViewById(R.id.ModuleDetailItemUnreadCount);
		if(this.getItem(position).containsKey("unread"))
			textUnread.setText(this.getItem(position).get("unread"));
		else
			textUnread.setVisibility(View.INVISIBLE);
		
		if(position==1||position==2||position==5||position==6)
			view.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.module_item_bg_orange));
		return view;
	}
	
}